home *** CD-ROM | disk | FTP | other *** search
/ CD/PC Actual 76 / DVD Actual 1 Marzo 2003.iso / Trial / TurboCAD 7.1 Pro / Data.Cab / F24443_MDDlog2.cpp < prev    next >
Encoding:
Text File  |  2000-11-10  |  1.6 KB  |  67 lines

  1. HRESULT GetImsigxPath(LPTSTR lpszPath)
  2. {
  3.     OLECHAR subKey[_MAX_PATH];
  4.  
  5.     wcscpy(subKey, L"CLSID\\");
  6.     OLECHAR* pGuid = wcschr(subKey, 0);
  7.     if (::StringFromGUID2(CLSID_XApplication, pGuid, _MAX_PATH) == 0)
  8.         return E_FAIL;
  9.     wcscat(subKey, L"\\InProcServer32");
  10.  
  11.     HKEY hKey;
  12.     if (::RegOpenKeyExW(
  13.         HKEY_CLASSES_ROOT,    // handle of open key 
  14.         subKey,    // address of name of subkey to open 
  15.         0,    // reserved 
  16.         KEY_READ,    // security access mask 
  17.         &hKey)     // address of handle of open key 
  18.         != ERROR_SUCCESS)
  19.         return E_FAIL;
  20.  
  21.     DWORD dwType;
  22.     DWORD dwData;
  23.     LONG lResult = ::RegQueryValueEx(
  24.         hKey,    // handle of key to query 
  25.         NULL,    // address of name of value to query 
  26.         NULL,    // reserved 
  27.         &dwType,    // address of buffer for value type 
  28.         (LPBYTE)lpszPath,    // address of data buffer 
  29.         &dwData);     // address of data buffer size 
  30.    
  31.     ::RegCloseKey(hKey);
  32.     return (lResult == ERROR_SUCCESS) ? S_OK : E_FAIL;
  33. }
  34.  
  35. void CMakeDwgDlg::OnInprocServer()
  36. {
  37.     TCHAR szIMSIGXDLL[_MAX_PATH];
  38.     HRESULT hRes = GetImsigxPath(szIMSIGXDLL);
  39.     if (SUCCEEDED(hRes))
  40.     {
  41.         hRes = E_FAIL;
  42.         HINSTANCE hMod = ::LoadLibrary(szIMSIGXDLL);
  43.         if (hMod != NULL)
  44.         {
  45.             HRESULT (*GetApp)(IApplication**) = 
  46.                 (HRESULT (*)(IApplication**))
  47.                 ::GetProcAddress(hMod, "IMSIGXGetXApplication");
  48.             if (GetApp != NULL)
  49.                 hRes = (*GetApp)(&m_pIApplication);
  50.             // ::FreeLibrary(szIMSIGXDLL);
  51.         }
  52.         else
  53.         {
  54.             DWORD dwLastError = GetLastError();
  55.             hRes = E_FAIL;
  56.         }
  57.     }
  58.  
  59.     if (FAILED(hRes))
  60.     {
  61.         AfxMessageBox("Couldn't create application object (in-process server)!");
  62.     }
  63.  
  64.     EnableButtons();
  65. }
  66.  
  67.